package test;

import static org.junit.Assert.*;

import java.util.Random;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import dsa.LinkedList;

public class AaronRudolphTest
{
	LinkedList list;
	
	int iterations = 10;
	
	@Before
	public void setUp() throws Exception
	{
		list = new LinkedList();
		
		for(int i = 0; i < iterations; i ++)
		{
			list.addLast(i);
		}
	}

	@After
	public void tearDown() throws Exception
	{
		
	}
	
	@Test
	public void AddLastTest()
	{
		Random rand = new Random();
		
		int checkIndex = rand.nextInt(iterations);
		
		assertTrue((Integer)list.get(checkIndex) == checkIndex);
	}
	
	@Test
	public void AddFirstTest()
	{
		list = new LinkedList();
		for(int i = iterations - 1; i >= 0; i --)
		{
			list.addFirst(i);
		}
		
		Random rand = new Random();
		
		int checkIndex = rand.nextInt(iterations);
		
		assertTrue((Integer)list.get(checkIndex) == checkIndex);
	}
	
	@Test
	public void RemoveTest()
	{
		Random rand = new Random();
		
		int checkIndex = rand.nextInt(iterations);
		
		assertTrue(checkIndex == (Integer)list.remove(checkIndex));
		
		for(int i = 0; i < iterations; i ++)
		{
			assertFalse((Integer)(list.get(i)) == (Integer)checkIndex);
		}
	}
	
	@Test
	public void SetTest()
	{
		Random rand = new Random();
		
		int checkIndex = rand.nextInt(iterations);
		
		int randValue = rand.nextInt();
		
		list.set(checkIndex, randValue);
		assertTrue((Integer)(list.get(checkIndex)) == randValue);
	}
	
	@Test
	public void IndexOfAndGetTest()
	{
		Random rand = new Random();
		
		int checkIndex = rand.nextInt(iterations);
		
		assertTrue(checkIndex == (Integer)list.get(checkIndex));
	}
	
	@Test
	public void ToArrayTest()
	{
		Object[] array = list.toArray();
		
		for(int i = 0; i < iterations; i ++)
		{
			assertTrue(array[i] == list.get(i));
		}
	}
}
